<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <div class="container">

    </div>
</body>

</html>
<script>
    let container = document.querySelector('.container')
    //1.获取当前页面的 浏览器中传递的producid参数

    //2.根据productid向后端发起请求,获取数据

    //3.获取数据之后渲染
function getQueryString(url){
    let cs=url.split("?")[1];
    if(!cs){
        return null;
    }
    let  csArr=cs.split("&");
    let csObj={};
    csArr.forEach(item =>{
        csObj[item.split("=")[0]]=item.split("=")[1]
    });
    return csObj;
}

let href = decodeURI(location.href)


var cs = getQueryString(href);

// console.log(cs.productId);

   
    // console.log(id)


    fetch("http://chst.vip:1234/api/getproduct?productid=6",{
        method:"get"
    })
    .then(body =>body.json())
    .then(res =>{
        let container = document.querySelector('.container')
        console.log(res);
        let text=""
        res.result.forEach(item=>{
            text +=`<div>`
        })
        container.innerHTML=text
    })
//    const xhr =new XMLHttpRequest();
// xhr.open("get","http://chst.vip:1234/api/getproduct?productid=1",true);
// xhr.send(null);
// xhr.onreadystatechange=function(){
//     if(xhr.readyState === 4){
//                 if(xhr.status === 200){
//                     let res = JSON.parse(xhr.responseText);
//                     console.log(res)
//                 }
//             }
// }
            // console.log(r)
        //     let regExp = /(?<=imgurl=)[^'"]*/;
        //     let url = r.productImg2.match(regExp);
        //     // console.log(url)
        //     let el = `<img src=${url[0]} alt="" />
        //     <div class="content">${r.productInfo1}</div>
        //     <div class="content">${r.productInfo2}</div>`

        //     container.innerHTML = el;
         
</script>